package cn.tedu.controller;

import cn.tedu.common.JsonResult;
import cn.tedu.config.PageData;
import cn.tedu.pojo.dto.ExperimentDTO;
import cn.tedu.pojo.param.ExperimentAddParam;
import cn.tedu.pojo.vo.ExperimentVO;
import cn.tedu.service.ExperimentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/experiment")
@Api(tags = "仪器模块")
public class ExperimentController {

    @Autowired
    private ExperimentService experimentService;

    @ApiOperation("创建仪器")
    @PostMapping("save")
    public JsonResult createExperiment(ExperimentAddParam equipmentAddParam) {
        log.debug("创建仪器-入参：{}",equipmentAddParam);
        experimentService.createExperiment(equipmentAddParam);
        log.debug("创建仪器-入参：{}",equipmentAddParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询仪器")
    @GetMapping("select")
    public JsonResult select(ExperimentDTO equipmentQuery) {
        log.debug("查询仪器-入参：{}",equipmentQuery);
        PageData data = experimentService.select(equipmentQuery);
        log.debug("查询仪器-:入参:{},出参:{}",equipmentQuery,data);
        return JsonResult.ok(data);
    }

    @ApiOperation("更新仪器状态")
    @PostMapping("/update/{serialNumber}/{isCertified}")
    public JsonResult updateStatus(@PathVariable Integer serialNumber,@PathVariable String isCertified){
        log.debug("更新状态:{}",serialNumber,isCertified);
        experimentService.updateStatus(serialNumber,isCertified);
        return JsonResult.ok();
    }

    @ApiOperation("删除仪器")
    @PostMapping("/delete/{serialNumber}")
    public JsonResult deleteEquipment(@PathVariable Integer serialNumber){
        log.debug("删除仪器:{}",serialNumber);
        experimentService.deleteEquipment(serialNumber);
        return JsonResult.ok();
    }

}
